package panda.query.aggr;

import panda.query.scan.Scanner;
import panda.query.struct.Attribute;
import panda.query.struct.Constant;
import panda.query.struct.NullConstant;
import panda.query.struct.SemAttribute;

/**
 * 
 * @author Tian Yuan
 *
 */
public class MaxFn implements AggregateFn {
	private Attribute attr;
	private Attribute nattr;
	private Constant result = null;
	
	public MaxFn(Attribute attr, Attribute nattr) {
		this.attr = attr;
		this.nattr = nattr;
	}

	public void first(Scanner s) {
		Constant t = s.getValue(attr); 
		if (!(t instanceof NullConstant)) result = t;
	}
	
	public void next(Scanner s) {
		Constant t = s.getValue(attr);
		if (!(t instanceof NullConstant) && (result == null || t.compareTo(result) > 0))
			result = t;
	}

	public Attribute getAttribute() {
		return nattr;
	}

	public Constant getValue() {
		return result;
	}


}
